package com.atguigu.v_blocking_queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);

        /*// 添加元素
        System.out.println(blockingQueue.add("a"));
        System.out.println(blockingQueue.add("b"));
        System.out.println(blockingQueue.add("c"));

        // 移除元素
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.remove());

        // 获取首元素
        System.out.println(blockingQueue.element()); // a*/

        /*// 添加
        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));
        System.out.println(blockingQueue.offer("x"));

        // 移除
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());

        // 获取首元素
        System.out.println(blockingQueue.peek());*/

        /*blockingQueue.put("a");
        blockingQueue.put("b");
        blockingQueue.put("c");
//        blockingQueue.put("x");

        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());*/

        System.out.println(blockingQueue.offer("a", 1L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.offer("b", 1L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.offer("c", 1L, TimeUnit.SECONDS));
//        System.out.println(blockingQueue.offer("x", 1L, TimeUnit.SECONDS));

        System.out.println(blockingQueue.poll(1L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll(1L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll(1L, TimeUnit.SECONDS));
        System.out.println(blockingQueue.poll(1L, TimeUnit.SECONDS));

    }
}
